﻿@{
    ViewBag.Title = "TimeClass";
}

@section scripts
{  
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script> 
}

   <div class="mini-splitter" style="width:100%;height:100%;">
       <div size="270" showcollapseButton="true">
            <div class="mini-fit">
               <ul id="tree1" class="mini-tree" style="width:100%;" expandOnLoad="0"
                  textField="FName" idField="FItemID" parentField="FParentID" showTreeIcon="true" resultAsTree="false">        
               </ul>
            </div>
        </div>

           <div showCollapseButton="true">
                <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
                    <table style="width:100%;">
                        <tr>
                            <td style="width:100%;">
                                <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                                <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBill" plain="true" visible="@ViewBag.cadd">新增</a>
                                <a class="mini-button" id="edit" name="edit" iconCls="icon-edit" onclick="modify" plain="true" visible="@ViewBag.cedit">修改</a>
                                <a class="mini-button" id="delrow" name="delrow" iconCls="icon-remove" onclick="removeRows" plain="true" visible="@ViewBag.cremove">删除</a>
                                 <span class="separator"></span>
                                <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                            </td>
                        </tr>
                    </table>       
                </div>
                <table>
                    <tr>
                        <td width ="100px" align="right">编码或名称: </td>
                        <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKey" name = "FSearchKey" onkeypress="setkeyPress()"/></td>
                        <td width ="100px" align="center">
                            <a class="mini-button" iconCls="icon-search" onclick="search(0)" plain="true">查询</a>
                        </td>
                    </tr>
                </table>
                <div class="mini-fit" >
                    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                            borderStyle="border:1;" url="../Member/TimeClassList"
                            allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                            onrowdblclick="modify"  sortMode="client">
                        <div property="columns">
                            <div type="checkcolumn" ></div>
                            <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                            <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">编码</div>
                            <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">名称</div>
                            <div field="FRemark" name="FRemark" width="120" headeralign="center" allowsort="true">备注</div>
                        </div>
                    </div>
                </div>
        </div>        

    </div>

<script>
    mini.parse();
    var tree = mini.get("tree1");
    var grid = mini.get("datagrid1");
    var json = "";

    function FormShown() {

        LoadListTree(0);
        tree.on("nodeselect", function (e) {
            LoadListData(0);
        });
        LoadListData(0);
    }
    function setkeyPress() {
        LoadListData(0);
    }
    function LoadListTree(c) {
        var sSystemAppID = parent.window.getSystemAppID();
        $.post('GetCTimeClass', { mjson: '[{"FSystemAppID":"'+sSystemAppID+'"}]' }, function (data) {
            tree.loadList(mini.decode(data));
            tree.select(0);
            if (c == 1)
                tree.collapseAll();
        });
    }

    function LoadListData(mdatatype) {
        var sSystemAppID = parent.window.getSystemAppID();
        var mload = tree.getData();
        if (mload.length > 0) {
            var node = tree.getSelectedNode();
            var classid = node.FItemID;
            json = "[{";
            json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
            json = json + "'mClassID':" + "'" + classid + "',";
            json = json + "'search':" + "'" + mini.getbyName("FSearchKey").getValue() + "'";
            json = json + "}]";
            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;
        }
    }

    function search(mdatatype) {
        LoadListData(mdatatype);
    }

    function newBill() {
        var uID = parent.window.getSystemAppID();
        var node = tree.getSelectedNode();
        if (node.FItemID == 0) {
            mini.alert("请选择一个分类再新增");
            return;
        }
        mini.open({
            url: "../Member/TimeClassInfo",
            title: "次卡分类", width: 600, height: 230,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0", FClassID: node.FItemID, FClassNumber: node.FNumber, FClassName: node.FName };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                grid.load({ mydata: json });
            }
        });
    }

    function modify() {
        if (!mini.get("edit").getVisible()) return;
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "../Member/TimeClassInfo",
                title: "次卡分类", width: 600, height: 230,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID, FClassID: row.FClassID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    function removeRows() {
        var row = grid.getSelected();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        SetRemoveRows();
                    }
                });
        } else {
            mini.alert("请选要删除的记录");
        }
    }

    function SetRemoveRows() {
        var FSystemAppID = parent.window.getSystemAppID();
        var rows = grid.getSelecteds();
        var json = "[";
        for (var i = 0; i < rows.length; i++) {
            if (i > 0)
                json = json + ',';
            js = '{"FItemID":' + rows[i].FItemID + '}';
            json = json + js
        }
        json = json + "]";
        if (json.length < 8) {
            mini.alert("没有要保存的数据！");
            return;
        }
        $.post("RemoveRows", { json: json, mSystemAppID: FSystemAppID }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                grid.reload();
            }
            else {
                mini.alert("出现错误，错误信息:" + ret.error);
            }
        });
    }

    function printBill() {
        var grid = mini.get("datagrid1");
        var url = "../Report/PrintReport";
        mini.open({
            url: url,
            title: "打印", width: 1000, height: 700,
            onload: function () {
                var iframe = this.getIFrameEl();
                var NoneDisplayCol = [0,1];
                iframe.contentWindow.InitalPrint(grid, NoneDisplayCol, parent.window.getSystemCompany() + "次卡分类");
            }
        });
    }

    function ExcelImport() {
        var FSystemAppID = parent.window.getSystemAppID();
        mini.open({
            url: "../data/Import.aspx?mDataType=9&mSystemAppID=" + FSystemAppID,
            title: "次卡分类导入", width: 420, height: 200
        });
    }

</script>